<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>注册</title>
    <link rel="stylesheet" href="css/reg.css">
    <style>
        .row  .telVal{width:44%;}
        .regForm .row{margin:0.1rem 0;}
        @media screen and (max-width: 321px){
            .row .inpVal{width:37%;}
            .sendNumBtn{width:30%;}
        }
    </style>
    <script src="js/jquery-1.8.3.min.js"></script>
    <script src="layer/mobile/layer.js"></script>

</head>
<body>
    <div class="container">
        <div class="content">
            <form class="regForm">

                <!--电话-->
                <div class="row">
                   <label for="phone" class="regLable" name="phone"><span style="color:#f3f3f3;">话话</span>电话：</label>
                    <input type="text" name="phone" class="inpVal telVal" placeholder="请输入手机号"><span readonlyunselectable="on" readonly class="sendNumBtn" >获取验证码</span>
                </div>
                <!--验证码-->
                <div class="row">
                    <label for="code" class="regLable" name="code"><span style="color:#f3f3f3;">话</span>验证码：</label>
                    <input type="text" name="code" class="inpVal codeVal telVal" placeholder="请输入验证码">
                    <input type="hidden" class="customerId">
                </div>
                <!--设置密码-->
                <div class="row">
                    <label for="code" class="regLable" name="password">设置密码：</label>
                    <input type="password" name="password1" class="inpVal telVal passVal" placeholder="请输入密码">
                </div>
                <!--确认密码-->
                <div class="row">
                    <label for="code" class="regLable" name="password">确认密码：</label>
                    <input type="password" name="password2" class="inpVal telVal passVal1" placeholder="请确认密码">
                </div>
                <!--昵称-->
                <div class="row">
                    <label for="code" class="regLable" name="code"><span style="color:#f3f3f3;">话话</span>昵称：</label>
                    <input type="password" name="password2" class="inpVal telVal nameVal" placeholder="请输入昵称">
                </div>
                <div class="row">
                    <input type="button" class="regBtn" value="确   定">
                </div>
            </form>
        </div>
    </div>


    <script>
        var countdown=60;
        function settime(obj) {
            if (countdown == 0) {
                obj.removeAttribute("disabled");
                obj.innerHTML="获取验证码";
                countdown = 60;
                return;
            } else {
                obj.setAttribute("disabled", true);
                obj.innerHTML=countdown +"s";
                countdown--;
            }
            setTimeout(function() {
                    settime(obj) }
                ,1000)
        }
        $(".telVal").blur(function(){
            $.post("http://192.168.0.5:8989/bulu/customer/isRegisted",{phone:$(".telVal").val()},function(data){
                var data2 = JSON.parse(data);
                console.log(data2.status);

                if(data2.status == 1 ){
                    //alert("222");
                    layer.open({
                        content: data2.message
                        ,skin: 'msg'
                        ,time: 2 //2秒后自动关闭
                    });

                }else{
                    $(".sendNumBtn").click(function(){
                        if($(".telVal").val() !== ""){
                            var re = /^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/;
                            var tel = $(".telVal").val();

                            var retu=re.test(tel);
                            if(!retu){
                                layer.open({
                                    content: '请输入正确格式的手机号'
                                    ,skin: 'msg'
                                    ,time: 2 //2秒后自动关闭
                                });
                                $(".telVal").val("");
                                return false;
                            }else{
                                //lkb0.lukebang.com.cn
                                $.post("http://192.168.0.5:8989/bulu/upload/sendMaByPhone",{sendType:3,phone:tel},function(data){
                                    //console.log(data);
                                    /*if(data.status==0){
                                     alert("验证码已发送您的手机，请注意查收！");
                                     $(".regLable").attr("number",data.data);
                                     }*/
                                },"json")
                                settime(this);
                                return true;
                            }
                        }else{
                            layer.open({
                                content: '请输入手机号'
                                ,skin: 'msg'
                                ,time: 2 //2秒后自动关闭
                            });
                            //alert("请输入手机号");
                        }
                    })
                }
            })
        })


        /*点击注册验证手机号*/

        //var reg = /(1[3-9]\d{9}$)/;
        //var re=new RegExp(/^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/);


        $(".regBtn").click(function(){
            if($(".telVal").val() == ""){
                layer.open({
                    content: '请输入手机号'
                    ,skin: 'msg'
                    ,time: 2 //2秒后自动关闭
                });
                return false;
            }else if($(".codeVal").val() == ""){
                layer.open({
                    content: '请输入验证码'
                    ,skin: 'msg'
                    ,time: 2 //2秒后自动关闭
                });
            } else if($(".passVal").val() == ""){
                layer.open({
                    content: '请输入密码'
                    ,skin: 'msg'
                    ,time: 2 //2秒后自动关闭
                });
            } else if($(".passVal1").val() == ""){
                layer.open({
                    content: '请确认密码'
                    ,skin: 'msg'
                    ,time: 2 //2秒后自动关闭
                });
            } else if($(".nameVal").val() == ""){
                layer.open({
                    content: '请输入昵称'
                    ,skin: 'msg'
                    ,time: 2 //2秒后自动关闭
                });
            }else{
                var tel = $(".telVal").val();
                var re = /^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)$/;
                var retu=re.test(tel);
                if(!retu){
                    //alert("请输入正确格式的手机号");
                    layer.open({
                        content: '请输入正确格式的手机号'
                        ,skin: 'msg'
                        ,time: 2 //2秒后自动关闭
                    });
                    return false;
                }else{
                    var codeNum = $(".codeVal").val();
                    var hideNum = $(".customerId").val();
                    if($(".passVal").val() != $(".passVal1").val()){
                        layer.open({
                            content: '密码不一致请重新输入!'
                            ,skin: 'msg'
                            ,time: 2 //2秒后自动关闭
                        });
                    }else{
                        $.post("http://192.168.0.5:8989/bulu/customer/subordinate",{customerId:1000016,phone:tel,vertifyCode:codeNum},function(data){
                            var data = JSON.parse(data);
                            console.log(typeof (data.status) );
                            if(data.status == 0){
                                layer.open({
                                    content: data.message
                                    ,skin: 'msg'
                                    ,time:5//2秒后自动关闭
                                });
                            }else{
                                layer.open({
                                    content: data.message
                                    ,skin: 'msg'
                                    ,time:5//2秒后自动关闭
                                });
                            }
                        })
                        $(this).attr("disabled","true");
                        setTimeout('$(".regBtn").removeAttr("disabled")',3000);
                    }

                    //lalert("222");
                    return true;
                }

            }
        })
    </script>
</body>
</html>